a = 0
n = input()
if len(n) != 4:
    print(0)
    exit() 
for i in range(4, 0, -1): 
    for j in range(i):
        x = int(n[j:i]) 
        flag = False
        for l in range(2, x // 2 + 1):
            if x % l == 0:
                flag = True
                break
        if not flag:
            if x > a:
                a = x
print(a)